
define(["./dom", "./builder", "_"], function(dom, builder, _) {
  var FADE_DURATION, display, exports, floatingConsole, level, nativeConsole;
  nativeConsole = {};
  floatingConsole = null;
  FADE_DURATION = 0.25;
  exports = {
    DURATION: 10
  };
  try {
    nativeConsole = console;
  } catch (e) {

  }
  display = function(className, message) {
    var div, removed, runFadeout;
    if (!floatingConsole) {
      floatingConsole = builder(".t-console");
      dom.body().prepend(floatingConsole);
    }
    div = builder(".t-console-entry." + className, dom.escapeHTML(message));
    floatingConsole.append(div.hide().fadeIn(FADE_DURATION));
    removed = false;
    runFadeout = function() {
      return div.fadeOut(FADE_DURATION, function() {
        if (!removed) {
          return div.remove();
        }
      });
    };
    window.setTimeout(runFadeout, exports.DURATION * 1000);
    return div.on("click", function() {
      div.remove();
      return removed = true;
    });
  };
  level = function(className, consolefn) {
    return function(message) {
      if (!consolefn) {
        display(className, message);
        return;
      }
      if (_.isFunction(consolefn)) {
        consolefn.call(console, message);
      } else {
        consolefn(message);
      }
    };
  };
  exports.debugEnabled = (document.documentElement.getAttribute("data-debug-enabled")) != null;
  exports.debug = exports.debugEnabled ? level("t-debug", nativeConsole.debug || nativeConsole.log) : function() {};
  exports.info = level("t-info", nativeConsole.info);
  exports.warn = level("t-warn", nativeConsole.warn);
  exports.error = level("t-err", nativeConsole.error);
  return exports;
});
